package com.junzhiit.nengji.api.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.VipService;
import com.junzhiit.nengji.api.web.vo.ResultVO;
import com.junzhiit.nengji.api.web.vo.VipAddVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/vip")
public class VipController {

	@Autowired
	private VipService vipService;
	
	@ApiOperation(value = "查询渠道合伙人身份")
	@RequestMapping(value = "/channel",method = RequestMethod.GET)
	public ResultVO getVipByIdentity(Integer identity){
		return vipService.getVipByIdentity(identity);
	}
	
	@ApiOperation(value = "购买身份")
	@RequestMapping(value = "/pay",method = RequestMethod.POST)
	public ResultVO wechatPay(HttpServletRequest request,VipAddVO vo){
		ResultVO result = new ResultVO();
		AssertUtil.notNull(vo.getUserId(), "userId is required.");
		AssertUtil.notNull(vo.getTradeType(), "tradeType is required.");
		AssertUtil.notNull(vo.getUserName(), "userName is required.");
		AssertUtil.notNull(vo.getMobilePhone(), "mobilePhone is required.");
		AssertUtil.notBlank(vo.getCityId(), "cityId is required.");
		result = vipService.payVip(vo, request);
		return result;
	}
	
	@ApiOperation(value = "删除userVIP记录")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO delete(String userVipId){
		AssertUtil.notBlank(userVipId, "userVipId is required.");
		return vipService.delete(userVipId);
	}
}
